package thread;

public class Main {

    public static volatile boolean isShutDown = false;

    public static void main(String[] args) throws Exception {
        Thread mainThead = Thread.currentThread();

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            try {
                isShutDown = true;
                while (mainThead.getState() != Thread.State.TERMINATED) {
                    System.out.println(mainThead.getState());
                    System.out.println(Thread.currentThread().getState());
                    Thread.sleep(1000);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }));

//        while (!isShutDown) {
//            Thread.sleep(1000);
//        }
        System.out.println("main thread exit.");
        System.exit(0);
    }
}
